package com.zhangx.datastructure.lineartable;

/**
 * @ClassName MyLinkList
 * @Description TODO
 * @Author zhangx
 * @Date 2020/12/23 8:49
 **/
public class MyLinkList {

    private Node linkList;

    public MyLinkList(){
        Node first = new Node();
        first.data = -1;

        Node n1 = new Node();
        n1.data = 1;

        Node n2 = new Node();
        n2.data = 2;

        Node n3 = new Node();
        n3.data = 3;

        first.next = n1;
        n1.next = n2;
        n2.next = n3;

        linkList = first;
    }

    public Node getElem(int index){
        int i = 0;
        Node now = linkList;
        while (now.next!=null){
            if (index == i){
                return now;
            }
            i++;
            now = now.next;
        }
        return null;
    }

    @Override
    public String toString() {
        return "MyLinkList{" +
                "linkList=" + linkList +
                '}';
    }

    public static void main(String[] args) {
        MyLinkList myLinkList = new MyLinkList();
        Node n = myLinkList.getElem(0);
        System.out.println(n.data);
    }

    class Node{
        int data;
        Node next;
    }
}
